<?php
/**
* @version $Id: plgContentSearchTag.php 1.5
* @copyright Joe Guo
* @license GNU/GPLv2,
* @author Joe Guo - http://www.eboga.org
*/
defined( '_JEXEC' ) or  die('Restricted access');
jimport( 'joomla.event.plugin' );


class plgContentSearchTag extends JPlugin
{
	function plgContentSearchTag( &$subject, $params )
		{
		   parent::__construct( $subject, $params );	
		}	
	
	function onContentPrepare($context, &$article, &$params, $limitstart) 
	{	
	  if ((JRequest :: getVar('view')) == 'article'){
        
		  $links = '';
		  $keys = explode( ',', $article->metakey );
		  foreach ($keys as $key) {
		  $key = trim( $key );
        if($key==''){
            continue;
        }
		  if ($key) { 
		       $searchphrase=$this->param('searchphrase');
		       if(!$searchphrase){
                $searchphrase='all';		       
		       }
				 $link="index.php?option=com_search&areas[]=content&searchphrase=".$searchphrase."&searchword=";
				 $link.=urlencode($key);
				 $link=JRoute::_($link);
				 $links.="<a href='".$link."'>".$key."</a>&nbsp;&nbsp;"; 
		  }
		}
		if ($links!=""){
		  $cssStyle=$this->param('cssStyle');
		  if($cssStyle){
		     $article->text.="<br><br><div class='".$cssStyle."'>Tags: ". $links ."</div>";
		  }else{
		     $align=$this->param('align');
		     $alignStyle="";
		     if($align!='none'){
		       $alignStyle=" align='".$align."'";
		     }
		     $article->text.="<br><br><div ".$alignStyle." style='background-color:#efefef';>Tags: ". $links ."</div>";
		  }
		}
     
    }//end if JRequest
	  return true;
	}
	
	   function param($name, $default='') {
    	return $this->params->get($name,$default);
        
    }
	
}
?>
